package com.zhouhailin;

import java.util.Optional;
import java.util.function.Predicate;

/**
 * Optional中 map() 方法与 filter() 方法结合使用
 *
 * @Author zhouhailin
 * @date 2023/1/19 11:13
 */
public class OptionalMapFilterDemo {
    public static void main(String[] args) {
        String password = "password";
        Optional<String> optionalS = Optional.ofNullable(password);

        // 要求密码是 6到10 位
        Predicate<String> len6 = pwd -> pwd.length() > 6;
        Predicate<String> len10 = pwd -> pwd.length() < 10;
        Predicate<String> eq = pwd -> pwd.equals("password");

        boolean result = optionalS.map(String::toLowerCase).filter(len6.and(len10).and(eq)).isPresent();
        System.out.println(result);
    }
}
